Open a file for reading and writing.
The following example opens a file for reading and writing.
C# .NET |
public static String DoTest() { string strRet = ""; string path = @"c:\temp\MyTestOpenWrite.txt"; // Delete the file if it exists. if (!File.Exists(path)) { // Create the file. FileStream fs = File.Create(path); fs.Close(); } // Open the stream and read it back. FileStream fs1 = File.OpenWrite(path); Byte[] info = new UTF8Encoding(true).GetBytes("This is to test the OpenWrite method."); // Add some information to the file. fs1.Write(info, 0, info.Length); fs1.Close(); // Open the stream and read it back. FileStream fs2 = File.OpenRead(path); byte[] b = new byte[1024]; UTF8Encoding temp = new UTF8Encoding(true); while (fs2.Read(b,0,b.Length) > 0) { strRet += (temp.GetString(b) + Environment.NewLine); } fs2.Close(); return strRet; } |
Blaze++ .NET |
static String DoTest() { String strRet = ""; String path = "c:\\temp\\MyTestOpenWrite.txt"; // Delete the file if it exists. if (!File::Exists(path)) { // Create the file. FileStream fs = File::Create(path); fs.Close(); } // Open the stream and read it back. FileStream fs1 = File::OpenWrite(path); byteA info = UTF8Encoding(true).GetBytes("This is to test the OpenWrite method."); // Add some information to the file. fs1.Write(info, 0, info.Length); fs1.Close(); // Open the stream and read it back. FileStream fs2 = File::OpenRead(path); byteA b(1024); UTF8Encoding temp(true); while (fs2.Read(b,0,b.Length) > 0) { strRet += (temp.GetString(b) + Environment::NewLine); } fs2.Close(); return strRet; } |